Skip to contentMethod: CompositeEntityUserActionProvider(Entity, AudioExplorerPresentationControlSpi)
1: /*
2: * *********************************************************************************************************************
3: *
4: * blueMarine II: Semantic Media Centre
5: * http://tidalwave.it/projects/bluemarine2
6: *
7: * Copyright (C) 2015 - 2021 by Tidalwave s.a.s. (http://tidalwave.it)
8: *
9: * *********************************************************************************************************************
10: *
11: * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with
12: * the License. You may obtain a copy of the License at
13: *
14: * http://www.apache.org/licenses/LICENSE-2.0
15: *
16: * Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on
17: * an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the
18: * specific language governing permissions and limitations under the License.
19: *
20: * *********************************************************************************************************************
21: *
22: * git clone https://bitbucket.org/tidalwave/bluemarine2-src
23: * git clone https://github.com/tidalwave-it/bluemarine2-src
24: *
25: * *********************************************************************************************************************
26: */
27: package it.tidalwave.bluemarine2.ui.audio.explorer.impl;
28:
29: import javax.annotation.Nonnull;
30: import it.tidalwave.util.NotFoundException;
31: import it.tidalwave.role.Composite;
32: import it.tidalwave.role.ui.UserAction;
33: import it.tidalwave.role.ui.spi.DefaultUserActionProvider;
34: import it.tidalwave.dci.annotation.DciRole;
35: import it.tidalwave.bluemarine2.model.spi.Entity;
36: import lombok.RequiredArgsConstructor;
37: import static it.tidalwave.role.SimpleComposite._SimpleComposite_;
38:
39: /***********************************************************************************************************************
40: *
41: * A default role for {@link Entity} instances in the context of {@link DefaultAudioExplorerPresentationControl} and
42: * containing a {@link Composite} role that provides a default action for that navigates inside the composite contents.
43: *
44: * FIXME: it should be only injected in entities with the Composite role, but the DCI Role library is not capable of
45: * navigating inside data; in other words, @DciRole(datumType = ...) can only refer to a datum class.
46: *
47: * As a workaround, since this role is a factory of {@link UserAction}s, it just refuses to create them in case there's
48: * no Composite.
49: *
50: * @stereotype Role
51: *
52: * @author Fabrizio Giudici
53: *
54: **********************************************************************************************************************/
55: @DciRole(datumType = Entity.class, context = DefaultAudioExplorerPresentationControl.class)
56: @RequiredArgsConstructor
57: public class CompositeEntityUserActionProvider extends DefaultUserActionProvider
58: {
59: @Nonnull
60: private final Entity mediaFolder;
61:
62: @Nonnull
63: private final AudioExplorerPresentationControlSpi control;
64:
65: @Override @Nonnull
66: public UserAction getDefaultAction()
67: throws NotFoundException
68: {
69: // test for the Composite role
70: // FIXME: Composite doesn't work. Introduce Composite8?
71: mediaFolder.maybeAs(_SimpleComposite_).orElseThrow(NotFoundException::new);
72: return UserAction.of(() -> control.navigateTo(mediaFolder));
73: }
74: }